const Service = require('egg').Service;

class wechatMsgService extends Service {
  async replyRule(wechatData) {
      if(wechatData!=null&&wechatData.MsgType!=null){
        switch (wechatData.MsgType) {
            case 'text':
                let replyText;
                if(wechatData.Content === '小熊哔哔哔'){
                    replyText = '安兹·乌尔·恭';
                }
                return await this.replyText(wechatData,replyText);
                break;
            default:
                return '';
                break;
          }
      }

  }
  async replyText (wechatData,replyText){
      if(replyText != null && replyText != ""){
        let replyObject = {};
        replyObject.ToUserName = wechatData.FromUserName;
        replyObject.FromUserName  = wechatData.ToUserName;
        replyObject.CreateTime = Date.now();
        replyObject.MsgType = 'text';
        replyObject.Content = replyText;
        return this.ctx.helper.wechatJson2Xml(replyObject);
      }else{
          return '';
      }
  }

  async replyVoice (wechatData){

  }
}

module.exports = wechatMsgService;
